# 编译器设置
CC = clang
GO = go

# 编译标志
CFLAGS = -O2 -g -Wall -target bpf -c
GOFLAGS = -tags ebpf

# 目标文件
EBPF_OBJ = ssl_ebpf.o
GO_BINARY = ssl_monitor
TEST_BINARY = test_ssl

# 默认目标
all: $(GO_BINARY)

# 编译 eBPF 程序
$(EBPF_OBJ): ssl_ebpf.c
	$(CC) $(CFLAGS) -o $@ $<

# 生成 Go 绑定代码
generate: $(EBPF_OBJ)
	$(GO) generate

# 编译 Go 程序
$(GO_BINARY): generate
	$(GO) build $(GOFLAGS) -o $@ main.go

# 编译测试程序
$(TEST_BINARY): test_ssl.go
	$(GO) build -o $@ $<

# 清理
clean:
	rm -f $(EBPF_OBJ) $(GO_BINARY) $(TEST_BINARY) ssl_ebpf.go

# 安装依赖
deps:
	$(GO) mod tidy
	$(GO) mod download

# 测试依赖
test-deps: test_deps.go
	$(GO) run test_deps.go

# 运行程序（需要 root 权限）
run: $(GO_BINARY)
	sudo ./$(GO_BINARY)

# 运行测试程序
test: $(TEST_BINARY)
	./$(TEST_BINARY)

.PHONY: all clean deps test-deps run test generate 